<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Grouped product data template
 *
 * @see Mage_Catalog_Block_Product_View_Media
 * @see Mage_Catalog_Block_Product_View_Type_Grouped
 */
?>
<script type="text/javascript">
		optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<script type="text/javascript">
//<![CDATA[
	// var productAddToCartForm = new VarienForm('product_addtocart_form');
	// productAddToCartForm.submit = function(){
			// if (this.validator.validate()) {
					// //this.form.submit();
					// url=$('product_addtocart_form').action;
					// ajaxUpdate(url,'form');
			// }
	// }.bind(productAddToCartForm);
//]]>
</script>
<?php
    $_helper = $this->helper('catalog/output');
    $_product = $this->getProduct();
?>
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
	<div class="no-display">
		<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
		<input type="hidden" name="related_product" id="related-products-field" value="" />
	</div>
	<div id="product-shop">
		<div class="product-options" id="product-options-wrapper" style="margin:0">
			<div class="product-name">
                <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
            </div>
				<?php $_associatedProducts = $this->getAssociatedProducts() ?>
				<?php if($_product->isSaleable() && count($_associatedProducts)): ?>
					<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
				<?php else: ?>
					<p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
				<?php endif; ?>
				<?php echo $this->getChildHtml('product_type_data_extra') ?>
				<table class="data-table grouped-items-table" id="super-product-table">
					<col />
					<col />
					<col width="1" />
					<thead>
						<tr>
							<th><?php echo $this->__('Product Name') ?></th>
							<th class="a-right"><?php echo $this->__('Price') ?></th>
							<?php if ($_product->isSaleable()): ?>
							<th class="a-center"><?php echo $this->__('Qty') ?></th>
							<?php endif; ?>
						</tr>
					</thead>
					<tbody>
					<?php if (count($_associatedProducts)): ?>
					<?php foreach ($_associatedProducts as $_item): ?>
						<?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
						<tr>
							<td><?php echo $this->htmlEscape($_item->getName()) ?></td>
							<td class="a-right">
								<?php echo $this->getPriceHtml($_item, true) ?>
								<?php echo $this->getTierPriceHtml($_item) ?>
							</td>
							<?php if ($_product->isSaleable()): ?>
							<td class="a-center">
							<?php if ($_item->isSaleable()) : ?>
								<input type="text" name="super_group[<?php echo $_item->getId() ?>]" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
							<?php else: ?>
								<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
							<?php endif; ?>
							</td>
							<?php endif; ?>
						</tr>
					<?php endforeach; ?>

					<?php else: ?>
					   <tr>
						   <td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
					   </tr>
					<?php endif; ?>
					</tbody>
				</table>
		</div>
	</div>
		<div style="margin:10px 0px 40px 0px">
			<?php echo $this->getChildHtml('addtocart');?>
			<a href="javascript:void(0);" id="btcancel" onclick = "$('product_addtocart_form').remove();$('options').setStyle({display:'none'});">
				<?php echo $this->__('Cancel')?>
			</a>
		</div>
		<script type="text/javascript">decorateTable('super-product-table')</script>
</form>
